/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bussiness;
import DatabaseAccess.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
/**
 *
 * @author mrhung
 */
public class ChungLoai {
    private String Machungloai;
    private String Chungloai;
    private DBHelper conn = new DBHelper();

    /**
     * @return the Machungloai
     */
    public String getMachungloai() {
        return Machungloai;
    }

    /**
     * @param Machungloai the Machungloai to set
     */
    public void setMachungloai(String Machungloai) {
        this.Machungloai = Machungloai;
    }

    /**
     * @return the Chungloai
     */
    public String getChungloai() {
        return Chungloai;
    }

    /**
     * @param Chungloai the Chungloai to set
     */
    public void setChungloai(String Chungloai) {
        this.Chungloai = Chungloai;
    }

    /**
     * @return the conn
     */
   public ChungLoai(){}
    public ChungLoai(String Machungloai, String Chungloai){
        this.setMachungloai(Machungloai);
        this.setChungloai(Chungloai);
       
    }
     public int InsertChungloai(ChungLoai a) throws SQLException
    {
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMachungloai());
            v.add(a.getChungloai());
            i=conn.executeUpdate("sp_InsertChungloai",v);
        }catch(SQLException ex){}
        return i;
    }
      public int UpdateChungLoai(ChungLoai a) throws SQLException
    {
        DBHelper obj =new DBHelper();
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMachungloai());
            v.add(a.getChungloai());
            i=obj.executeUpdate("sp_UpdateChungLoai",v);
        }catch(SQLException ex){}
        return i;
    }
    public int DelChungLoai(String Machungloai) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(Machungloai);            
            i=conn.executeUpdate("sp_DelChungLoai",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
      public Vector getAllChungLoai() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = conn.executeQuery("sp_getALLChungloai");
            while(rs.next())
            {                  
                ChungLoai b = new ChungLoai();
                b.setMachungloai(rs.getString(1));
                b.setChungloai(rs.getString(2));
                v.add(b);                         
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;
    }
      public Vector getChungLoai_Machungloai(String Machungloai) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(Machungloai);
        try{
            ResultSet rs = conn.executeQuery("sp_getMachungloai", v1);
            while(rs.next()){
                ChungLoai b = new ChungLoai();
                b.setMachungloai(rs.getString(1));
                b.setChungloai(rs.getString(2));
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v; 
    }
       public Vector getChungLoai_Chungloai(String Chungloai) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(Chungloai);
        try{
            ResultSet rs = conn.executeQuery("sp_getChungloai", v1);
            while(rs.next()){
                ChungLoai b = new ChungLoai();
                b.setMachungloai(rs.getString(1));
                b.setChungloai(rs.getString(2));
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v;
    }
}
